package qrcodeGeneretor;

import java.io.File;
import java.io.FileOutputStream;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.Code128Writer;
import com.google.zxing.qrcode.QRCodeWriter;

public class QRCODE {
	public static final String NUMERIC_STRING_100 = "01234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890";
	public static final String NUMERIC_STRING_500 = NUMERIC_STRING_100
			+ NUMERIC_STRING_100 + NUMERIC_STRING_100
			+ NUMERIC_STRING_100 + NUMERIC_STRING_100;
	public static final String NUMERIC_STRING_1000 = NUMERIC_STRING_500
			+ NUMERIC_STRING_500;

	public static final String NUMERIC_STRING_2000 = NUMERIC_STRING_1000
			+ NUMERIC_STRING_1000;
	
	public static final String NUMERIC_STRING_2001 = NUMERIC_STRING_1000 + "1"
			+ NUMERIC_STRING_1000;

	public static final String NUMERIC_STRING_4000 = NUMERIC_STRING_2000 + "1"
			+ NUMERIC_STRING_2000;

	
	public static void generateQRCODE(String data, String fileName) {
		int width = 600;
		int height = 600;

		BitMatrix bitMatrix;
		try {
			QRCodeWriter qrCodeWriter = new QRCodeWriter();
//			qrCodeWriter.
			bitMatrix = qrCodeWriter.encode(data, BarcodeFormat.QR_CODE,
					width, height, null);
			MatrixToImageWriter.writeToStream(bitMatrix, "png",
					new FileOutputStream(new File(fileName + ".png")));
		} catch (WriterException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void generateBarcode128() {
		int width = 440;
		int height = 48;

		BitMatrix bitMatrix;
		try {
			bitMatrix = new Code128Writer().encode("Hello World !!!",
					BarcodeFormat.CODE_128, width, height, null);
			MatrixToImageWriter.writeToStream(bitMatrix, "png",
					new FileOutputStream(
							new File("/home/kas/zxing_barcode.png")));
		} catch (WriterException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
